<template>
  <div class="set">
    <group>
      <cell title="我的余额" :value="'￥'+(supplierData.balance?supplierData.balance:'0.00')"></cell>
    </group>
    <group>
      <cell title="名称" @click.native="change({title:'修改供应商名称',placeholder:'请填写名称',change_name:'supplier_name'})" :value="supplierData.supplier_name" is-link></cell>
      <cell title="身份证信息" :value="supplierData.idcard" :link="{name:'ID_information'}" is-link></cell>
      <cell title="营业执照信息" :link="{name:'license_information'}" is-link></cell>
    </group>
    <group>
      <cell title="负责人" @click.native="change({title:'修改负责人名称',placeholder:'请填写名称',change_name:'charge'})" :value="supplierData.charge" is-link></cell>
      <cell title="负责人联系电话" @click.native="change({title:'修改负责人联系电话',placeholder:'请填写联系电话',change_name:'charge_phone'})" :value="supplierData.charge_phone" is-link></cell>
    </group>
    <group>
      <cell title="修改密码" :link="{name:'EditPassword'}" is-link></cell>
    </group>
    <group>
      <cell title="退出登录" @click.native="logout" style="text-align:center;"></cell>
    </group>
  </div>
</template>
<script>
import { Group, Cell } from "vux";
export default {
  name: "set",
  data() {
    return {
      supplierData:{}
    };
  },
  methods: {
    logout() {
      this.$http.get("/api/supplier.Login_out/index").then(res => {
        if (res.data.code) {
          this.$vux.toast.show({
            text:res.data.msg
          })
          this.$router.push({ name: "login" });
        }
      });
    },
    change(options){
      var _this = this
      var supplierData = JSON.parse(JSON.stringify(this.supplierData)); 
      this.$vux.confirm.prompt(options.placeholder,{
        title:options.title,
        onConfirm (msg) {
          supplierData[options.change_name] = msg
          _this.$http.post('/api/supplier.supplier/update',supplierData).then(res=>{
            if(res.data.code){
              _this.supplierData[options.change_name] = msg
              _this.$vux.toast.show({
                text:'修改成功'
              })
            }
          })
        }
      })
    }
  },
  created(){
    this.$http.get("/api/supplier.supplier/read").then(res=>{
      this.supplierData = res.data.data
    })
  },
  components: {
    Group,
    Cell
  }
};
</script>
<style scoped>

</style>